<?php


namespace App\Service;

use App\Model\Enum\StatusEnum;

/**
 * Class MchInfoStatusService
 * 商户信息状态检测
 *
 * @package App\Service
 */
class MchInfoStatusService {

    /**
     * 商户信息是否可用
     *
     * @param $mch
     *
     * @throws \Exception
     */
    public function verifyAvailable ($mch) {

        if (!$mch) {
            throw new \Exception(trans('pay.mch.not_found'));
        }

        if ($mch['status'] != StatusEnum::ON) {
            throw new \Exception(trans('pay.mch.not_active'));
        }
    }

    /**
     * 注册信息是否审核通过
     *
     * @param $mch
     *
     * @throws \Exception
     */
    public function verifyApprove ($mch) {

        $this->verifyAvailable($mch);

        if ($mch['regStatus'] != 1) {
            throw new \Exception(trans('pay.mch.not_review'));
        }
    }

    /**
     * 商户能否使用API
     *
     * @param $mch
     *
     * @throws \Exception
     */
    public function verifyApiAvailable ($mch) {

        $this->verifyApprove($mch);

        if ($mch['apiStatus'] != StatusEnum::ON) {
            throw new \Exception(trans('pay.mch.not_support_api'));
        }
    }



}
